package com.cao.controller;

import com.cao.service.JdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Author: huahua
 * @Date: 2021-04-13 23:09
 */
@RestController
@RequestMapping("content")
public class ContentController {

    @Autowired
    private JdService jdService;

    @RequestMapping("/parse/{keywords}")
    public boolean parse(@PathVariable("keywords") String keywords) throws IOException {
        if (keywords == "" || keywords == null) {
            return false;
        } else {
            return jdService.parseContent(keywords);
        }

    }

    @RequestMapping("/search/{from}/{size}/{keywords}")
    public List<Map<String, Object>> search(@PathVariable("from") Integer from
            , @PathVariable("size") Integer size
            , @PathVariable("keywords") String keywords) throws IOException {

        System.out.println(jdService.searchPage(from, size, keywords));
        return jdService.searchPage(from, size, keywords);

    }
}
